package butines.game2.entity;



public class Animation {

    private float timer;
    private int frame;
    
    private boolean running;
    private boolean starting;
    
    public Animation() {
        
    }
    
    public void restart() {
        starting = false;
    }

    public boolean animate(float dt, float frameRate, int length, boolean looping) {
        if (!starting) {
            frame = 0;
            timer = frameRate;
            running = true;
            starting = true;
        }
        if (!running) {
            return false;
        }
        timer -= dt;
        if (timer <= 0) {
            timer = frameRate;
            if (frame + 1 < length - 1) {
                frame++;
            } else if (looping) {
                frame = 0;
            } else {
                running = false;
                return false;
            }
        }
        return true;
    }

    public float getTimer() {
        return timer;
    }

    public int getFrame() {
        return frame;
    }

    public boolean isRunning() {
        return running;
    }
    
}
